<?php
error_reporting(1);
$pl=1;
$color=array(
    "#BEBEBE",
    "#FF60AF",
    "#FF77FF",
    "#CA8EFF",
    "#9393FF",
    "#84C1FF",
    "#80FFFF",
    "#93FF93",
    "#FFFF6F",
    "#FFBB77",
    "#CF9E9E",
    "#95CACA",
    "#CA8EC2)"
);
$map = array(
	turn=>1,
    wi=>4,
    he=>3,
    "army"=>array(
        1=>array(
            1=>array(
                x=>1,
                y=>1,
                pep=>1000,
                nm=>"第一军团"
            ),
            2=>array(
                x=>1,
                y=>2,
                pep=>900,
                nm=>"第二军团"
            ),
            3=>array(

                x=>1,
                y=>3,
                pep=>1000,
                nm=>"第三军团"
            ),
            4=>array(

                x=>1,
                y=>4,
                pep=>900,
                nm=>"第四军团"
            ),
        ),
        2=>array(
            1=>array(
                x=>2,
                y=>1,
                pep=>1000,
                nm=>"国民警卫队"
            )
        )
    ),
    "money"=>array(
        1=>10000,
        2=>10000,
        3=>10000,
        4=>10000,
        5=>10000
    ),
    "pl"=>array(
        1=>"sigaide",
        2=>"",
        3=>"",
        4=>"",
        5=>""
    ),
    "cap"=>array(
        1=>[1,1],
        2=>[2,1],
        3=>[2,3],
        4=>[3,1],
        5=>[4,4]
    ),
    "country"=>array(
        1=>"邵帝帝国",
        2=>"美利坚合众国",
        3=>"塔利班组织",
        4=>"日就洛帝国",
        5=>"sigaide大佬"
    ),
    "dx"=>array(
        1=>"艾登平原",
        2=>"东南山地",
        3=>"超级盆地",
        4=>"日落山",
        5=>"sigaide大佬的别墅"
    ),
    1 => array(
        1=>array(
            own=>1,
            bey=>1,
            bld=>0
        ),
        2=> array(
            own=>1,
            bey=>1,
            bld=>0
        ),
        3=> array(
            own=>1,
            bey=>1,
            bld=>0
        ),
        4=> array(
            own=>1,
            bey=>1,
            bld=>0
        ),
    ),
    2 => array(
        1=>array(
            own=>2,
            bey=>2,
            bld=>0
        ),
        2=> array(
            own=>2,
            bey=>2,
            bld=>0
        ),
        3=> array(
            own=>3,
            bey=>3,
            bld=>0
        ),
        4=> array(
            own=>3,
            bey=>3,
            bld=>0
        ),
    ),
    3 => array(

        1=>array(
            own=>4,
            bey=>4,
            bld=>0
        ),
        2=> array(
            own=>4,
            bey=>4,
            bld=>0
        ),
        3=> array(
            own=>4,
            bey=>4,
            bld=>0
        ),
        4=> array(
            own=>5,
            bey=>5,
            bld=>0
        ),

    )
);
session_start();
$_SESSION['w']=$map;
$_SESSION['p']=$pl;
?>

<html>
<body>
<script src="jquery-3.5.1.min.js"></script>
<div style="position: fixed;left:80%;top:1%;z-index:3"><p id="mm">金币</p></div>
<div style="position: fixed;z-index:3"></div>

<div style="z-index:999999;left:15%;width:70%;top:80%;text-align:center;position:fixed;opacity:60%;background-color:white" id="tmm">
结束
</div>
<div id='bd' style='z-index:2;visibility:hidden;position:fixed;background-color:gray;width:70%;height:70%;left:15%;top:15%;opacity:90%;background-color:white'>
    <button style="position:absolute;top:1%;left:97%" onclick="kk()">×</button>
    <strong>管理部队</strong>
    <table id="bdd">

    </table>
</div>
<button id="adf" style="z-index:4;position:absolute;top:6%;left:1%" onclick="gl()"><<<</button>

<div id='gl' style='z-index:2;position:fixed;background-color:gray;width:40%;height:90%;left:0%;top:5%;opacity:90%;background-color:white'>
	<div style="position:absolute;top:3%">

    <button class="g" onclick="bb()">购买部队</button>    
    <?php
    include("usr.php");
    ?>    
    <?php
    //include("chat.php");
    ?>
    </div>
</div>
<div id='bddd' style='z-index:2;visibility:hidden;position:fixed;background-color:gray;width:70%;height:70%;left:15%;top:15%;opacity:90%;background-color:white'>
    <button style="position:absolute;top:1%;left:97%" onclick="kk()">×</button>
    <strong>选择攻击部队</strong>
    <table id="bdddd">

    </table>
</div>
<div id="bkg" style="z-index:9;position:fixed;top:0%;left:0%;height:100%;width:100%;background-color: black;opacity: 50%;visibility: hidden"></div>
<div id='ask' style='z-index:10;visibility:hidden;position:fixed;background-color:gray;width:70%;height:70%;left:15%;top:15%;opacity:90%;background-color:white'>
    <div style="z-index:99">
    <button style="position:absolute;top:1%;left:94%" onclick="kk()">×</button>
    <h2>确认框</h2>
    <strong id="qrv"></strong><br/>
    <button class="aa" onclick="ok()">确定</button>
    <button class="aa" onclick="kk()">取消</button>
    </div>
</div>
<div id='inp' style='z-index:10;visibility:hidden;position:fixed;background-color:gray;width:70%;height:70%;left:15%;top:15%;opacity:90%;background-color:white'>
    <div style="z-index:99">
    <button style="position:absolute;top:1%;left:94%" onclick="kk()">×</button>
    <h2>输入框</h2>
    <strong id="qrvv"></strong><br/>
    <p id="ak">请输入合并后的新部队名</p><input id="in"/>
    <button class="aa" onclick="okk()">确定</button>
    <button class="aa" onclick="kk()">取消</button>
    </div>
</div>
<div id='ene' style='visibility:hidden;z-index:2;position:fixed;width:70px;opacity:70%;background-color:white'>
    <p id="info1"></p>
    <strong>操作</strong>
    <button class="cs1" onclick="atta()">攻击</button>
    <button class="cs1">轰炸</button>
</div>
<div id='my' style='visibility:hidden;z-index:2;position:fixed;width:70px;opacity:70%;background-color:white'>
    <p id="info2"></p>
    <strong>操作</strong>
    <button onclick="bd()" class="cs1">管理军队</button>
</div>
<div id="di"></div>
<script language="javascript">
 window.onerror = function(errorMessage, scriptURI, lineNumber,columnNumber,errorObj) { 
 a="";
    a+=("错误信息：" +errorMessage); 
    a+=("出错文件：" + scriptURI); 
    a+=("出错行号：" +lineNumber); 
    a+=("出错列号：" + columnNumber); 
    a+=("错误详情：" + errorObj); 
    alert(a);
  } 
</script>
<script language="javascript">
    hei=0,wid=0,me=0;
    last="";
    ism=false;
    bdmm=0;
    mi=0,mj=0,oo=0;
    function dis(a){
    	if(document.getElementById(a).style.visibility == "visible"){document.getElementById(a).style.visibility = "hidden";return true}
    	else document.getElementById(a).style.visibility = "visible";
    	return false;
    
    }
    function gl(){
    if(dis("gl"))document.getElementById("adf").innerText=">>>";
    else document.getElementById("adf").innerText="<<<";
    }
    window.onload=function (){
        ref();
    }
    function ref() {
		
        jQuery.ajax({
            type: "POST",
            url: 'service.php',
            data: {functionname: 'getda', arguments: []},
            success:function(data) {
                eval(data.toString());
            }
        });
        jQuery.ajax({
            type: "POST",
            url: 'service.php',
            data: {functionname: 'ref', arguments: []},
            success:function(data) {
                document.getElementById("di").innerHTML=data;
            }
        });
    }
    function ask(a,b){

        document.getElementById("bkg").style.visibility = "visible"
        document.getElementById("ask").style.visibility = "visible"
        document.getElementById("qrv").innerText=a;

    }
    function hid(){
        document.getElementById("my").style.visibility = "hidden"
        document.getElementById("ene").style.visibility = "hidden";
        for(var i=1;i<=hei;i++){
            for(var j=1;j<=wid;j++){
                document.getElementById("a"+i+"j"+j).style.visibility = "hidden";
            }
        }
    }
    function cc(i,j,o) {
        mi=i;mj=j;mo=o;
       hid();
        

        if(ism==true||o==-2){

        
            jQuery.ajax({
                type: "POST",
                url: 'service.php',
                data: {functionname: 'bdmov', arguments: [i,j,bdmm]},
                success:function(data) {
                    if(data.toString()=="e3"){
                        msg("您在一回合内不能把攻击部队移动那么远。");
                        return;
                    }
                    if(data.toString()=="e1"){
                        msg("您在一回合内不能把部队移动那么远。");
                        return;
                    }                    
                    if(data.toString()=="还没轮到您操作!"){
                        msg("未轮到您操作。");
                        return;
                    }
                   
                    if(data.toString()=="e2"){
                        msg("您的金币不足");
                        return;
                    }
                    
                    ask(data.toString());
                    ok=function(){
                    kk();
                    jQuery.ajax({
                            type: "POST",
                            url: 'service.php',
                            data: {functionname: 'bdmovr', arguments: [i,j,bdmm]},
                            success:function(data) {
                                msg(data.toString());
                                hid();
                                ref();
                                ism=false;
                                bdmm=0;
                            }
                        });
                    }
                }
            });
        }
                mov(i,j,o);
    }
    function cf(n,m){
		bdm=n;
    	document.getElementById("inp").style.visibility = "visible";
    	document.getElementById("qrvv").innerHTML = "您确定拆分"+m+"吗？";
    	document.getElementById("ak").innerText="请输入拆分出的新部队名";
    }
    function bb(){
document.getElementById("in").value=1;
    	document.getElementById("inp").style.visibility = "visible";
    	document.getElementById("qrvv").innerHTML = "您确定创建部队吗？";
    	document.getElementById("ak").innerText="请输入创建的部队数(100金币可以买100名士兵)";
    }
    function hb(i,j){
    	mi=i;mj=j;
    	document.getElementById("inp").style.visibility = "visible";
    	document.getElementById("qrvv").innerHTML = "您确定合并这个地块上的所有部队吗？";
    	document.getElementById("ak").innerText="请输入合并后的新部队名";
    }
   bn="",bdd=0;
    function okk(){
    	if(document.getElementById("ak").innerText=="请输入合并后的新部队名"){
        jQuery.ajax({
            type: "POST",
            url: 'service.php',
            data: {functionname: 'hb', arguments: [mi,mj,document.getElementById("in").value]},
            success:function(data) {
                msg(data);
            }
        });
        }
    	if(document.getElementById("ak").innerText=="请输入创建的部队名"){
        jQuery.ajax({
            type: "POST",
            url: 'service.php',
            data: {functionname: 'cb', arguments: [bn,document.getElementById("in").value]},
            success:function(data) {
                msg(data);
            }
        });
        }
        if(document.getElementById("ak").innerText=="请输入创建的部队数(100金币可以买100名士兵)"){
        	bn=(document.getElementById("in").value);
        	document.getElementById("ak").innerText="请输入创建的部队名";
        	document.getElementById("in").value="新部队";
        	return;
        }
        if(document.getElementById("ak").innerText=="请输入拆分出的新部队名"){
        	bn=(document.getElementById("in").value);
        	document.getElementById("ak").innerText="请输入您要拆分出的部队数";
        	document.getElementById("in").value=1;
        	return;
        }
        else if(document.getElementById("ak").innerText=="请输入您要拆分出的部队数"){
        	jQuery.ajax({
            type: "POST",
            url: 'service.php',
            data: {functionname: 'cf', arguments: [bdm,bn,document.getElementById("in").value]},
            success:function(data) {
                msg(data);
            }
       		});
        }
        kk();
        document.getElementById("in").value="";
    
    }
    function mov(i,j,o) {
    mi=i;mj=j;
        if(o===me){
            document.getElementById("my").style.left = document.getElementById("a"+i+"j"+j).style.left
            document.getElementById("my").style.top = (i+1) * 50 +document.getElementById("a"+i+"j"+j).clientHeight
            document.getElementById("ene").style.visibility = "hidden";
            document.getElementById("my").style.visibility = "visible"
        }else{
            document.getElementById("ene").style.left = document.getElementById("a"+i+"j"+j).style.left
            document.getElementById("ene").style.top = (i+1) * 50 +document.getElementById("a"+i+"j"+j).clientHeight
            document.getElementById("ene").style.visibility = "visible"
            document.getElementById("my").style.visibility = "hidden";
        }
    }
    function pbm(i,j){

        document.getElementById("my").style.visibility = "hidden";
        document.getElementById("ene").style.visibility = "hidden";
    }
    function cli(i){
        hid();
        if(document.getElementById(i).style.visibility == "visible")	{
            document.getElementById("my").style.visibility = "hidden";
            document.getElementById("ene").style.visibility = "hidden";
        }else{
            document.getElementById(i).style.visibility = "visible"
            document.getElementById("my").style.visibility = "hidden";
            document.getElementById("ene").style.visibility = "hidden";
        }
    }
    dd=new Array;
    rr=false;
    function cug(id) {
        if(dd[id]===3){
            return;
        }
        document.getElementById(id).innerHTML=document.getElementById(id).innerHTML+"<div style='display: inline-block; width: 100%; height: 100%;top:0px;left:0px;opacity: 0%;position:absolute;background-color: white' id='"+id+"t"+"' ></div>";
        dd[id]=3;
        rr=true;
        var aa=0,tim=0,rim=0;
        var ab=setInterval(function () {
            if (tim > 90)
                clearTimeout(ab);
            tim++;aa=aa+3;
            document.getElementById(id+"t").style.opacity=aa+'%'

        }, 16);


        var ba=setInterval(function () {
            if(tim<90)return;
            if(rim > 90){
                clearTimeout(ba);
                return;
            }
            if (rim === 90){
                rr=false;
                ba="";
                dd[id]=1;
                ii=-1;
            }
            rim++;
            aa=aa-3;
            document.getElementById(id+"t").style.opacity=aa+'%'

            // alert(im)
        }, 16);
    }
    function kk(){
document.getElementById("bddd").style.visibility = "hidden"
       document.getElementById("inp").style.visibility = "hidden"
        
        document.getElementById("bkg").style.visibility = "hidden"
        document.getElementById("bd").style.visibility = "hidden"
        document.getElementById("ask").style.visibility = "hidden"
    }
    function bd(){

        jQuery.ajax({
            type: "POST",
            url: 'service.php',
            data: {functionname: 'gets', arguments: [mi,mj]},
            success:function(data) {
            	
                eval(data.toString());
            }
        });
        hid();
        document.getElementById("bd").style.visibility = "visible"
    }
    function movv(i){
        bdmm=i;
        document.getElementById("bd").style.visibility = "hidden"
        msg("请选择您要移到的地块");
        ism=true;
    }
    function atta(){
    	jQuery.ajax({
            type: "POST",
            url: 'service.php',
            data: {functionname: 'getaa', arguments: [mi,mj]},
            success:function(data) {
                eval(data.toString());
            }
        });hid();
        document.getElementById("bddd").style.visibility = "visible"
  
    }
    onsid=false;
    function msg(s) {
        if(onsid){
            clearTimeout(attf);
        }
        onsid=true;
        document.getElementById("tmm").style.visibility = "visible" ;
        var dd=1;
        document.getElementById("tmm").innerHTML = s ;
        document.getElementById("tmm").style.opacity = 1;
        attf=setInterval(function () {
            if (dd <= 0)
            {document.getElementById("tmm").style.opacity = 0;onsid=false;document.getElementById("tmm").style.visibility ="hidden";clearTimeout(attf);}
            dd = dd - 0.01;
            if (dd < 0.8)
                document.getElementById("tmm").style.opacity = dd;
        }, 40);
    }
    msg("欢迎来到矩阵战争");
</script>
</body>
</html>
